#include <iostream>
#include <mutex>
#include <thread>
#include <atomic>

#include <chrono>

using namespace std;
using namespace chrono;

atomic<bool> run {false};

void func01() {
    while (run.load()) {
        cout << "func01" << endl;
        this_thread::sleep_for(microseconds(100));
    }
    cout << "func01 stop" << endl;
}

void func02() {
    while (run.load()) {
        cout << "func02" << endl;
        this_thread::sleep_for(microseconds(100));
    }
    cout << "func02 stop" << endl;
}

int main() {
    cout << "init all thread!" << endl;
    jthread t1 {func01};
    jthread t2 {func02};

    cout << "all thread is running!" << endl;
    run = true;

    this_thread::sleep_for(milliseconds(1000));

    run = false;
    cout << "all thread is over!" << endl;

    return 0;
}
